package com.platform.modules.mall.controller.associtag;

import com.platform.common.utils.ValidUtils;
import com.platform.modules.mall.entity.MallAssociTagEntity;
import com.platform.modules.mall.service.IAssociTagDataChange;
import com.platform.modules.mall.service.MallAssociTagService;

import javax.annotation.Resource;

public abstract class AssociTagDataChangeAbs<T> implements IAssociTagDataChange<T> {

    @Resource
    MallAssociTagService tagService;

    /**
     * 通用的删除方法
     * @param otherId
     * @return
     */
    @Override
    public boolean delate(String... otherId){
        if(otherId != null && otherId.length > 0){
            tagService.lambdaUpdate().in(MallAssociTagEntity::getOtherId,otherId).remove();
            this.associDelate(otherId);
        }
        return true;
    }

    public boolean addVerify(String associId, String goodsId){
        ValidUtils.allNotNull(associId,goodsId);
        // 删除掉旧标签
        if(tagService.lambdaQuery()
                .eq(MallAssociTagEntity::getAssociId,associId)
                .eq(MallAssociTagEntity::getOtherId,goodsId)
                .count() >= 1){
            return false;
        }
//        if(tagService.lambdaQuery().eq(MallAssociTagEntity::getAssociId,associId).count() >= 3){
//            // 同一个 associId 标签不能超过3个
//            return false;
//        }
        return true;
    }
}
